{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import csv\n",
    "import shutil\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "data_path = r\"E:\\project\\cv\\Deep-Emotion\\data\\dataset.csv\"\n",
    "dataset = []\n",
    "with open(data_path, 'r') as csv_file:\n",
    "    csv_reader = csv.reader(csv_file)\n",
    "    for line in csv_reader:\n",
    "        dataset.append(line)\n",
    "labels_list = []\n",
    "for i in range(1,len(dataset)):\n",
    "    labels_list.append(dataset[i][0])\n",
    "# one_hot = pd.get_dummies(labels_list)\n",
    "# one_hot_list = []\n",
    "# for idx,data in one_hot.iterrows():\n",
    "#     label = np.array(data)\n",
    "#     one_hot_list.append(label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_dataset(dataset, begin, end):\n",
    "    labels_file = open(r'E:\\project\\cv\\Deep-Emotion\\data\\{}.txt'.format(dataset), 'w')\n",
    "    src_path = r'E:\\project\\cv\\Deep-Emotion\\data\\dataset'\n",
    "    dst_path = r'E:\\project\\cv\\Deep-Emotion\\data\\{}'.format(dataset)\n",
    "    n = 0\n",
    "    for i in range(begin, end):\n",
    "        src_file = os.path.join(src_path, 'train{}.jpg'.format(i))\n",
    "        dst_file = os.path.join(dst_path, '{}.jpg'.format(n))\n",
    "        # print(src_file)\n",
    "        # print(dst_file)\n",
    "        shutil.copy(src_file, dst_file)\n",
    "        labels_file.write('{} {}\\n'.format(n, labels_list[i]))\n",
    "        n += 1\n",
    "        # writer.writerow(one_hot_list[i])\n",
    "\n",
    "    labels_file.close()\n",
    "        \n",
    "create_dataset('val', 0, 2871)\n",
    "create_dataset('test', 2871, 5742)\n",
    "create_dataset('train', 5742, 20096)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "val_txt_path = r\"E:\\project\\cv\\Deep-Emotion\\data\\val.txt\"\n",
    "\n",
    "with open(val_txt_path, 'r') as f:\n",
    "    s = f.readlines()\n",
    "\n",
    "# val_txt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2871"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0 0\\n', '1 0\\n', '2 2\\n']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "txt = s[889].split(' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['889', '4\\n'], '4')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "txt, txt[1][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "5cdd086b6fbefd3d66685ee501a3be08c01edfd680b5d4385ae6da7e3a0cf21a"
  },
  "kernelspec": {
   "display_name": "Python 3.8.12 64-bit ('dl': conda)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
